﻿namespace Gateway.Common.Models
{
    /// <summary>
    /// 自定义异常类
    /// </summary>
    public class MyException : Exception
    {
        /// <summary>
        /// 错误码
        /// </summary>
        public SystemErrorCode Code { get; set; }

        public new string Message { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public MyException()
        {

        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="message"></param>
        public MyException(string message) : base(message)
        {
            Message = message;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        public MyException(SystemErrorCode code, string message) : base(message)
        {
            Code = code;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        public MyException(int code, string message) : base(message)
        {
            Code = (SystemErrorCode)code;
            Message = message;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        public MyException(SystemErrorCode code)
        {
            Code = code;
            Message = EnumHelper.GetEnumDesc<SystemErrorCode>(code.GetHashCode());
        }


        /// <summary>
        /// 创建异常
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static MyException Create(SystemErrorCode code)
        {
            return new MyException(code);
        }

        /// <summary>
        /// 创建异常
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static MyException Create(SystemErrorCode code,string message)
        {
            return new MyException(code,message);
        }
        
        /// <summary>
        /// 创建异常
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static MyException Create(int code,string message)
        {
            return new MyException(code,message);
        }
    }
}